package com.hesicare.health.service.impl;

import com.hesicare.health.entity.SysBloodGlucose;
import com.hesicare.health.mapper.SysBloodGlucoseMapper;
import com.hesicare.health.service.ISysBloodGlucoseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 55097
 */
@Service
public class SysBloodGlucoseServiceImpl implements ISysBloodGlucoseService {

    @Autowired
    private SysBloodGlucoseMapper sysBloodGlucoseMapper;

    @Override
    public List<SysBloodGlucose> getBloodGlucose() {
        return sysBloodGlucoseMapper.selectSysBloodGlucoseById();
    }

    @Override
    public void updateBloodGlucose(Map<Long, Boolean> resultMap) {
        List<SysBloodGlucose> sysBloodGlucoseList = new ArrayList<>();
        if (!resultMap.isEmpty()) {
            for (Long key : resultMap.keySet()) {
                boolean value = resultMap.get(key);
                SysBloodGlucose sysBloodGlucose = new SysBloodGlucose();
                sysBloodGlucose.setId(key);
                if (value) {
                    sysBloodGlucose.setOperateState("1");
                } else {
                    sysBloodGlucose.setOperateState("2");
                }
                sysBloodGlucoseList.add(sysBloodGlucose);
            }
            sysBloodGlucoseMapper.updateSysBloodGlucose(sysBloodGlucoseList);
        }
    }
}
